home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume7 / image / part05 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  15.8 KB

  1. Subject:  v07i068:  Image manipulation routines in C++, Part05/05
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: David Sher <seismo!rochester!sher>
  6. Mod.sources: Volume 7, Issue 68
  7. Archive-name: image/Part05
  8.  
  9. [  The Makefiles had ESCAPE and \r characters in their comment lines;
  10.    I changed them to their printable representation, the two-character
  11.    sequences ^[ and ^M, respectively.  Also, the file ascii2var/uu.test.var
  12.    had some non-ASCII characters in it; I used uuencode; the resultant
  13.    file is really ascii2var/test.var.  Also, I do not have C++ nor any
  14.    images, so I have not tested this package.  --r$  ]
  15.  
  16. #!/bin/sh
  17. # This is a shell archive.  Remove anything before this line,
  18. # then unpack it by saving it in a file and typing "sh file".
  19. # If all goes well, you will see the message "No problems found."
  20. # Wrapped by mirror!rs on Mon Nov 10 13:45:52 EST 1986
  21.  
  22. # Exit status; set to 1 on "wc" errors or if would overwrite.
  23. STATUS=0
  24. # Contents:  vartools/makefile vartools/vartools.h++
  25. #    vartools/vartools.h vartools/cap.c++ MANIFEST
  26.  
  27. echo x - vartools/makefile
  28. if test -f vartools/makefile ; then
  29.     echo vartools/makefile exists, putting output in $$vartools/makefile
  30.     OUT=$$vartools/makefile
  31.     STATUS=1
  32. else
  33.     OUT=vartools/makefile
  34. fi
  35. sed 's/^X//' > $OUT <<'@//E*O*F vartools/makefile//'
  36. X# this is the makefile for the vartools library
  37.  
  38. X# This line constructs the library name (equal to the directory name)
  39. X# jccpwd^[!!sh^M:s/.*\///g^MILIBRARY = lib^[A.a^[
  40. XLIBRARY = libvartools.a
  41.  
  42. X.SUFFIXES: .c++ 
  43.  
  44.  
  45. XCFLAGS = -O -I/usr/grads/include
  46.  
  47. XC++FLAGS = -Fi $(CFLAGS)
  48.  
  49. XLIBS = -liff -lC
  50.  
  51. X# This line constructs the list of possible objects
  52. X# 2jc}ls *[A-Za-z0-9].c *.c++^[!!sh^M>}>}:g/\.c\+*$/ s//.o \\/^M
  53. XOBJS = \
  54. X    ascii2var.o \
  55. X    cap.o \
  56. X    correlate.o \
  57. X    scale.o \
  58. X    trunc.o \
  59. X    var2ascii.o 
  60.  
  61.  
  62. X.c++.o:
  63. X    c++ -c  $(C++FLAGS) $*.c++ 
  64.  
  65. X# the library is constructed by this line
  66. X$(LIBRARY) : $(OBJS)
  67. X    ar qv $(LIBRARY) $(OBJS)
  68. X    ranlib $(LIBRARY)
  69.  
  70. @//E*O*F vartools/makefile//
  71. chmod u=rw,g=r,o=r $OUT
  72.  
  73. echo x - vartools/vartools.h++
  74. if test -f vartools/vartools.h++ ; then
  75.     echo vartools/vartools.h++ exists, putting output in $$vartools/vartools.h++
  76.     OUT=$$vartools/vartools.h++
  77.     STATUS=1
  78. else
  79.     OUT=vartools/vartools.h++
  80. fi
  81. sed 's/^X//' > $OUT <<'@//E*O*F vartools/vartools.h++//'
  82. X/*
  83. X    This is the header file for all the utilities supplied
  84. X    in the vartools library
  85.  
  86. X    assumes that stdio.h has been included
  87. X*/
  88. X#ifndef VARTOOLS_H
  89. X#define VARTOOLS_H
  90.  
  91. X// needs this include file to have the image routines definition make sense
  92. X#include <double_image.h++>
  93. X#include <long_image.h++>
  94.  
  95. X/*
  96. X    This routine gets information from an iff file and constructs
  97. X    a var file from it
  98. X    comments is a null terminated string that sets up the
  99. X    comments for the var file
  100. X*/
  101. Xvoid
  102. Xiff2var(FILE *iff_file, FILE *var_file, char *comments);
  103.  
  104. X/*
  105. X    This routine gets information from a var file and constructs
  106. X    an iff file from it.
  107. X    This only works with graytone (integer) var files 
  108. X    To make a double var file into a graytone one use trunc
  109. X*/
  110. Xvoid
  111. Xvar2iff(FILE *var_file, FILE *iff_file);
  112.  
  113. X/*
  114. X    This converts a file in ascii format to a double var file
  115. X    ascii format is 2 dimensions followed by an appropriate number
  116. X    of doubles followed by comments
  117. X    input is a file pointer to the input file
  118. X    output is a file pointer open for output
  119. X*/
  120. Xvoid
  121. Xascii2var(FILE *input , FILE *output);
  122.  
  123. X/*
  124. X   This takes an initialized double image and outputs a file in ascii format
  125. X   described above
  126. X   input is an initialized image
  127. X   output is a file pointer open for output
  128. X   format is the format to output each number
  129. X*/
  130. Xvoid
  131. Xvar2ascii2(double_image& input , FILE *output , char *format );
  132.  
  133. X/*
  134. X    This is a version of var2ascii that takes an input file rather
  135. X    than an initialized image
  136. X*/
  137. Xvoid
  138. Xvar2ascii(FILE *input, FILE *output , char *format);
  139.  
  140. X/*
  141. X    Truncates an input image (takes floating point to long)
  142. X    needs a file to be output to
  143. X    but does not write to file
  144. X    instead returns the truncated image
  145. X*/
  146. Xlong_image&
  147. Xtrunc2( double_image& input , FILE *outfile );
  148.  
  149. X/*
  150. X    Truncates a double image into a graytone (integer image)
  151. X    Takes two files and reads from one to write to the other
  152. X    comment is a comment to be placed on the image
  153. X*/
  154. Xvoid
  155. Xtrunc( FILE *infile , FILE *outfile, char *comment);
  156.  
  157. X/*
  158. X    This takes an image as input and creates another
  159. X    It takes every pixel of the image and multiplies it by the
  160. X    scale and then adds to it the increment.
  161. X*/
  162. Xdouble_image&
  163. Xscale2(double scale, double increment, double_image& input, FILE *output_file);
  164.  
  165. X/*
  166. X    This takes two files and takes one and puts 
  167. X    a scaled and incremented version into the other
  168. X    comment will be placed in the comment for the output image
  169. X*/
  170. Xvoid
  171. Xscale(double scale, double increment, FILE *input, FILE *output, char * comment);
  172.  
  173. X/*
  174. X   this one takes 2 images and returns an image containing the 
  175. X   correlation of the input image with the template image
  176. X   it only returns values for the point where the template lies
  177. X   entirely within the input
  178. X*/
  179. Xdouble_image&
  180. Xcorrelate2(double_image& template, double_image& input, FILE *output_file);
  181.  
  182. X/*
  183. X   this one takes 2 image files and returns an image file containing the 
  184. X   correlation of the input image with the template image
  185. X   it only returns values for the point where the template lies
  186. X   entirely within the input
  187. X*/
  188. Xvoid
  189. Xcorrelate(FILE *template_file, FILE *input_file, FILE *output_file, char *comment);
  190.  
  191. X/*
  192. X    This code places an upper bound on the values of the pixels.
  193. X    If a pixel exceeds the bound it is set to the bound.
  194. X*/
  195. Xdouble_image&
  196. Xupper_bound2(double bound, double_image& input, FILE * output_file);
  197.  
  198. X/*
  199. X    This code places an lower bound on the values of the pixels.
  200. X    If a pixel exceeds the bound it is set to the bound.
  201. X*/
  202. Xdouble_image&
  203. Xlower_bound2(double bound, double_image& input, FILE * output_file);
  204.  
  205. X/*
  206. X    This code is like upper_bound2 but with files (for C)
  207. X*/
  208. Xvoid
  209. Xupper_bound(double bound, FILE * input_file, FILE * output_file, char *comment);
  210.  
  211. X/*
  212. X    This code is like lower_bound2 but with files (for C)
  213. X*/
  214. Xvoid
  215. Xlower_bound(double bound, FILE * input_file, FILE * output_file, char *comment);
  216.  
  217. X#endif VARTOOLS_H
  218. X/*
  219. XCopyright (C) 1986, David Sher in the University of Rochester
  220. XPermission is granted to any individual or institution to use, copy, or
  221. Xredistribute this software so long as it is not sold for profit, provided
  222. Xthis copyright notice is retained.
  223. X*/
  224. @//E*O*F vartools/vartools.h++//
  225. chmod u=rw,g=r,o=r $OUT
  226.  
  227. echo x - vartools/vartools.h
  228. if test -f vartools/vartools.h ; then
  229.     echo vartools/vartools.h exists, putting output in $$vartools/vartools.h
  230.     OUT=$$vartools/vartools.h
  231.     STATUS=1
  232. else
  233.     OUT=vartools/vartools.h
  234. fi
  235. sed 's/^X//' > $OUT <<'@//E*O*F vartools/vartools.h//'
  236. X/*
  237. X    This is the header file for all the utilities supplied
  238. X    in the vartools library
  239.  
  240. X    assumes that stdio.h has been included
  241. X*/
  242. X#ifndef VARTOOLS_H
  243. X#define VARTOOLS_H
  244.  
  245.  
  246. X/*
  247. X    This routine gets information from an iff file and constructs
  248. X    a var file from it
  249. X    comments is a null terminated string that sets up the
  250. X    comments for the var file
  251. X*/
  252. Xvoid
  253. Xiff2var(/* FILE *iff_file, FILE *var_file, char *comments */);
  254.  
  255. X/*
  256. X    This routine gets information from a var file and constructs
  257. X    an iff file from it.
  258. X    This only works with graytone (integer) var files 
  259. X    To make a double var file into a graytone one use trunc
  260. X*/
  261. Xvoid
  262. Xvar2iff(/* FILE *var_file, FILE *iff_file */);
  263.  
  264. X/*
  265. X    This converts a file in ascii format to a double var file
  266. X    ascii format is 2 dimensions followed by an appropriate number
  267. X    of doubles followed by comments
  268. X    input is a file pointer to the input file
  269. X    output is a file pointer open for output
  270. X*/
  271. Xvoid
  272. Xascii2var(/* FILE *input , FILE *output */);
  273.  
  274. X/*
  275. X   This takes an initialized double image and outputs a file in ascii format
  276. X   described above
  277. X*/
  278. Xvoid
  279. Xvar2ascii(/* FILE *input, FILE *output , char *format */);
  280.  
  281.  
  282. X/*
  283. X    Truncates a double image into a graytone (integer image)
  284. X    Takes two files and reads from one to write to the other
  285. X    comment is a comment to be placed on the image
  286. X*/
  287. Xvoid
  288. Xtrunc(/* FILE *infile , FILE *outfile, char *comment */);
  289.  
  290. X/*
  291. X    This takes an image file as input and creates another
  292. X    It takes every pixel of the image and multiplies it by the
  293. X    scale and then adds to it the increment.
  294. X*/
  295. Xvoid
  296. Xscale(/* double scale, double increment, FILE *input, FILE *output, char * comment */);
  297.  
  298. X/*
  299. X    This routine takes in a file for the template and a file for the
  300. X    input and outputs a file for the result of correlating the template
  301. X    with the image.   It only gets values for points where the template
  302. X    lies entirely within the input image.
  303. X    Comment will be placed within the comments.
  304. X*/
  305. Xvoid
  306. Xcorrelate(/* FILE *template_file, FILE *input_file, FILE *output_file, char *comment */);
  307.  
  308. X/*
  309. X    This code places an upper bound on the values of the pixels.
  310. X    If a pixel exceeds the bound it is set to the bound.
  311. X*/
  312. Xvoid
  313. Xupper_bound(/* double bound, FILE * input_file, FILE * output_file, char *comment */);
  314.  
  315. X/*
  316. X    This code places an lower bound on the values of the pixels.
  317. X    If a pixel exceeds the bound it is set to the bound.
  318. X*/
  319. Xvoid
  320. Xlower_bound(/* double bound, FILE * input_file, FILE * output_file, char *comment */);
  321.  
  322. X#endif VARTOOLS_H
  323. @//E*O*F vartools/vartools.h//
  324. chmod u=rw,g=r,o=r $OUT
  325.  
  326. echo x - vartools/cap.c++
  327. if test -f vartools/cap.c++ ; then
  328.     echo vartools/cap.c++ exists, putting output in $$vartools/cap.c++
  329.     OUT=$$vartools/cap.c++
  330.     STATUS=1
  331. else
  332.     OUT=vartools/cap.c++
  333. fi
  334. sed 's/^X//' > $OUT <<'@//E*O*F vartools/cap.c++//'
  335. X/*
  336. X    This is the routines that take the pixels of an image and place an
  337. X    upper or lower bound on them.
  338. X*/
  339.  
  340. X#include <stream.h>
  341. X#include <stdio.h>
  342. X#include <string.h>
  343. X#include <double_image.h++>
  344. X#include <vartools.h++>
  345.  
  346. X/*
  347. X    This code places an upper bound on the values of the pixels.
  348. X    If a pixel exceeds the bound it is set to the bound.
  349. X*/
  350. Xdouble_image&
  351. Xupper_bound2(double bound, double_image& input, FILE * output_file)
  352. X    {
  353. X    // create the image
  354. X    double_image *output_pointer = 
  355. X    new double_image(CREATE,input.n_rows(),input.n_cols(),output_file);
  356. X    double_image& output = *output_pointer;
  357. X    // iterate through the images copying when it is a good idea
  358. X    while(++input,++output)
  359. X    {
  360. X    double pixel = input();
  361. X    output() = (pixel > bound) ? bound : pixel;
  362. X    }
  363.  
  364. X    return output;
  365. X    }
  366.  
  367. X/*
  368. X    This code places an lower bound on the values of the pixels.
  369. X    If a pixel exceeds the bound it is set to the bound.
  370. X*/
  371. Xdouble_image&
  372. Xlower_bound2(double bound, double_image& input, FILE * output_file)
  373. X    {
  374. X    // create the image
  375. X    double_image *output_pointer = 
  376. X    new double_image(CREATE,input.n_rows(),input.n_cols(),output_file);
  377. X    double_image& output = *output_pointer;
  378. X    // iterate through the images copying when it is a good idea
  379. X    while(++input,++output)
  380. X    {
  381. X    double pixel = input();
  382. X    output() = (pixel < bound) ? bound : pixel;
  383. X    }
  384.  
  385. X    return output;
  386. X    }
  387.  
  388.  
  389. X/*
  390. X    This code is like upper_bound2 but with files (for C)
  391. X*/
  392. Xvoid
  393. Xupper_bound(double bound, FILE * input_file, FILE * output_file, char *comment)
  394. X    {
  395. X    // read in the input image
  396. X    double_image input(READ,input_file);
  397. X    // apply the upper bound to it and get the output
  398. X    double_image& output = upper_bound2(bound,input,output_file);
  399. X    // set up the comments
  400. X    output.set_comments(comment,strlen(comment));
  401. X    char *string = form("Applying Upper Bound of %e to image:\n",bound);
  402. X    output.add_comment(string,strlen(string));
  403. X    output.add_comment((char *) input.the_comments(),input.c_length());
  404. X    // write the result to file
  405. X    output.write();
  406. X    }
  407.  
  408. X/*
  409. X    This code is like lower_bound2 but with files (for C)
  410. X*/
  411. Xvoid
  412. Xlower_bound(double bound, FILE * input_file, FILE * output_file, char *comment)
  413. X    {
  414. X    // read in the input image
  415. X    double_image input(READ,input_file);
  416. X    // apply the upper bound to it and get the output
  417. X    double_image& output = lower_bound2(bound,input,output_file);
  418. X    // set up the comments
  419. X    output.set_comments(comment,strlen(comment));
  420. X    char *string = form("Applying Lower Bound of %e to image:\n",bound);
  421. X    output.add_comment(string,strlen(string));
  422. X    output.add_comment((char *) input.the_comments(),input.c_length());
  423. X    // write the result to file
  424. X    output.write();
  425. X    }
  426.  
  427. X/*
  428. XCopyright (C) 1986, David Sher in the University of Rochester
  429. XPermission is granted to any individual or institution to use, copy, or
  430. Xredistribute this software so long as it is not sold for profit, provided
  431. Xthis copyright notice is retained.
  432. X*/
  433. @//E*O*F vartools/cap.c++//
  434. chmod u=rw,g=r,o=r $OUT
  435.  
  436. echo x - MANIFEST
  437. if test -f MANIFEST ; then
  438.     echo MANIFEST exists, putting output in $$MANIFEST
  439.     OUT=$$MANIFEST
  440.     STATUS=1
  441. else
  442.     OUT=MANIFEST
  443. fi
  444. sed 's/^X//' > $OUT <<'@//E*O*F MANIFEST//'
  445. XMANIFEST                     5
  446. XREADME                       1
  447. Xascii2var                    1
  448. Xascii2var/main.c++           1
  449. Xascii2var/makefile           1
  450. Xascii2var/uu.test.var        1
  451. Xcopywrite                    1
  452. Xcorrelate                    1
  453. Xcorrelate/main.c++           1
  454. Xcorrelate/makefile           1
  455. Xlowerbound                   1
  456. Xlowerbound/main.c++          1
  457. Xlowerbound/makefile          1
  458. Xman                          1
  459. Xman/ascii2var.1              1
  460. Xman/correlate.1              2
  461. Xman/iff2var.1                1
  462. Xman/image.5                  1
  463. Xman/lowerbound.1             2
  464. Xman/scale.1                  2
  465. Xman/truncate.1               2
  466. Xman/upperbound.1             2
  467. Xman/var2ascii.1              2
  468. Xman/var2iff.1                1
  469. Xman/vartools.3               2
  470. Xscale                        1
  471. Xscale/main.c++               2
  472. Xscale/makefile               2
  473. Xtruncate                     1
  474. Xtruncate/main.c++            2
  475. Xtruncate/makefile            2
  476. Xupperbound                   1
  477. Xupperbound/main.c++          2
  478. Xupperbound/makefile          2
  479. Xvar2ascii                    1
  480. Xvar2ascii/main.c++           2
  481. Xvar2ascii/makefile           2
  482. Xvarc++                       1
  483. Xvarc++/archive.h++           2
  484. Xvarc++/bitio.h++             2
  485. Xvarc++/char_image.h++        2
  486. Xvarc++/double_image.c++      4
  487. Xvarc++/double_image.h++      3
  488. Xvarc++/error.h++             2
  489. Xvarc++/for.h++               3
  490. Xvarc++/iff_image.h++         3
  491. Xvarc++/iff_local.h++         3
  492. Xvarc++/iff_stdim.h++         3
  493. Xvarc++/image.c++             4
  494. Xvarc++/image.c.old           4
  495. Xvarc++/image.h++             3
  496. Xvarc++/long_image.c++        4
  497. Xvarc++/long_image.h++        3
  498. Xvarc++/makefile              3
  499. Xvarc++/var.h++               3
  500. Xvarc++/var_double_image.c++     3
  501. Xvarc++/var_image.c++         3
  502. Xvarc++/var_long_image.c++     3
  503. Xvartools                     1
  504. Xvartools/README              3
  505. Xvartools/ascii2var.c++       3
  506. Xvartools/cap.c++             5
  507. Xvartools/correlate.c++       4
  508. Xvartools/makefile            5
  509. Xvartools/scale.c++           4
  510. Xvartools/trunc.c++           4
  511. Xvartools/var2ascii.c++       3
  512. Xvartools/vartools.h          5
  513. Xvartools/vartools.h++        5
  514. @//E*O*F MANIFEST//
  515. chmod u=rw,g=rw,o=rw $OUT
  516.  
  517. echo Inspecting for damage in transit...
  518. temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
  519. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  520. cat > $temp <<\!!!
  521.       34      93     641 makefile
  522.      142     661    4189 vartools.h++
  523.       87     425    2548 vartools.h
  524.       98     382    2994 cap.c++
  525.       69     138    2143 MANIFEST
  526.      430    1699   12515 total
  527. !!!
  528. wc  vartools/makefile vartools/vartools.h++ vartools/vartools.h vartools/cap.c++ MANIFEST | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  529. if test -s $dtemp ; then
  530.     echo "Ouch [diff of wc output]:"
  531.     cat $dtemp
  532.     STATUS=1
  533. elif test $STATUS = 0 ; then
  534.     echo "No problems found."
  535. else
  536.     echo "WARNING -- PROBLEMS WERE FOUND..."
  537. fi
  538. exit $STATUS
  539.